<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class='form-group'>
                <input type="hidden" name="id" id="id">
                <input type="hidden" id="discardType" name="discardType">
                <label class='col-md-4 control-label'>人员</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='handlerId' id='handlerId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='人员' type='text'
                           name='handlerName' id='handlerName'
                           readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields( 'user', 'user', '用户', false, false, 'handlerId:id', 'handlerName:nickname', 'deployComeId:deptId', 'deployComeName:deptName')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>

            <div class='form-group'>
                <label class='col-md-4 control-label'>部门</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='deployComeId' id='deployComeId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='部门' type='text'
                           name='deployComeName' id='deployComeName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showSpecialTree('deployComeId', 'deployComeName', 'dept', '部门', 'root', 'select','fasDeptTree', true, true)">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>商品</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='goodsId' id='goodsId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='商品' type='text'
                           name='goodsName' id='goodsName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields('fas/goods','goods', '商品', true, false, 'goodsId:id', 'goodsName:name')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>类型</label>
                <div class='col-md-8'>
                    <select class="form-control input-sm selectpicker show-tick" name="handleType" id="handleType"
                            title="类型" data-live-search="true"></select>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>数量</label>
                <div class='col-md-8'>
                    <input class='form-control' placeholder='明细数量' type='text' name='detailNum' id='detailNum'
                           data-bv-notempty='true' data-bv-notempty-message='明细数量 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>备注</label>
                <div class='col-md-8'>
                    <textarea class="form-control" placeholder="备注" name="remark" id="remark"></textarea>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <!--<button class="btn btn-primary" onclick="location.href='handOverList.html'">返回</button>-->
                        <button class="btn btn-primary" type="submit" onclick="save()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript" src="/js/jq.js"></script>
<script type="text/javascript" src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/dict.js"></script>
<script type="text/javascript" src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/js/my/ztree-menu.js"></script>
<script type="text/javascript">
    $(function () {
        $('#form').bootstrapValidator();
        showDictSelect('handleType', 'discard_type', '--请选择--', '');
        initData();
    });

    function initData() {
        var id = getUrlParam("id");
        if (id != '') {
            $.ajax({
                type: 'get',
                url: '/handOver/' + id,
                async: false,
                success: function (json) {
                    if (json.code === 0) {
                        var data = json.data;
                        $('#id').val(data.id);
                        $('#discardType').val(data.discardType);
                        $('#handlerId').val(data.handlerId);
                        $('#handlerName').val(data.handlerName);
                        $('#handleType').val(data.handleType);
                        $('#deployComeId').val(data.deployComeId);
                        $('#deployComeName').val(data.deployComeName);
                        $('#goodsId').val(data.goodsId);
                        $('#goodsName').val(data.goodsName);
                        $('#detailNum').val(data.detailNum);
                        $('#remark').val(data.remark);
                    }
                }
            });
        }
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });
    // layui.use(['layer','laydate'], function(){
    //     var layer = layui.layer;
    // });
    /* var pro = window.location.protocol;
     var host = window.location.host;
     var domain = pro + "//" + host;

     var layedit, index;
     layui.use(['layedit','upload'], function(){
         layedit = layui.layedit;
         layedit.set({
             uploadImage: {
                 url: '/files/layui?domain=' + domain,
                 type: 'post'
             }
         });
         index = layedit.build('remarks');
     });*/
    function save() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

        var formdata = $("#form").serializeObject();

        $.ajax({
            type: 'post',
            url: '/handOver/discard',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                if (data.code == 0) {
                    var id = getUrlParam("id");
                    var msg = "";
                    if (id != '') {
                        msg = "修改成功";
                    } else {
                        msg = "添加成功";
                    }
                    layer.msg(msg, {shift: -1, time: 1000}, function () {
                        parent.location.reload();
                    });
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }

</script>
</body>
</html>
